<!DOCTYPE HTML>
<html  lang="zh" xmlns:th="http://www.thymeleaf.org">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-product-add">
			<div class="form-group">
				<label class="col-sm-3 control-label">厂商编号：</label>
				<div class="col-sm-8">
					<select id="gardenNo" name="gardenNo"  class="form-control m-b" th:with="type=${@garden.getGarden()}">
	                    <option th:each="garden : ${type}" th:text="${garden.gardenName+garden.teaGardenNo}" th:value="${garden.teaGardenNo}"></option>
	                </select>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">产品类型：</label>
				<div class="col-sm-8">
					<select id="productType" name="productType" class="form-control m-b" th:with="type=${@dict.getType('gh_product_type')}">
	                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
	                </select>
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">数量：</label>
				<div class="col-sm-8">
					<input id="amount" name="amount" class="form-control" type="text">
				</div>
			</div>
			<!-- 
			<div class="form-group">	
				<label class="col-sm-3 control-label">产品唯一识别码：</label>
				<div class="col-sm-8">
					<input id="productCode" name="productCode" class="form-control" type="text">
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">更新时间：</label>
				<div class="col-sm-8">
					<input id="updateTime" name="updateTime" class="form-control" type="text">
				</div>
			</div>
			 -->
			<div class="form-group">	
				<label class="col-sm-3 control-label">备注：</label>
				<div class="col-sm-8">
					<input id="remark" name="remark" class="form-control" type="text">
				</div>
			</div>
		</form>
	</div>
    <div th:include="include::footer"></div>
    <script type="text/javascript">
		var prefix = ctx + "module/product"
		$("#form-product-add").validate({
			rules:{
				gardenNo:{
					required:true,
				},
				productType:{
					required:true,
				},
				amount:{
					required:true,
					isDigits:true
				},
			}
		});
		
		function submitHandler() {
	        if ($.validate.form()) {
	           /*  $.operate.save(prefix + "/add", $('#form-product-add').serialize()); */
	           add();
	        }
	    }
		  function add() {
	        	var gardenNo = $("#gardenNo option:selected").val();
	        	var productType = $("#productType option:selected").val();
	        	var amount = $("input[name='amount']").val();
	        	var remark = $("input[name='remark']").val();
	        	
	        	if(parseInt(amount) == 0){
	        		 layer.open({
	        			  title: '提示信息',
	        			  content: '数量必须大于0 !',
	        			  icon:0
	        			});  
	        		return;
	        	}
	        /* 	var deptId = $("input[name='deptId']").val();
	        	var loginName = $("input[name='loginName']").val();
	        	var userName = $("input[name='userName']").val();
	        	var password = $("input[name='password']").val();
	        	var email = $("input[name='email']").val();
	        	var phonenumber = $("input[name='phonenumber']").val();
	        	var sex = $("#sex option:selected").val();
	        	var status = $("input[name='status']").is(':checked') == true ? 0 : 1;
	        	var roleIds = $.form.selectCheckeds("role");
	        	var postIds = $.form.selectSelects("post"); */
	        	$.ajax({
	        		cache : true,
	        		type : "POST",
	        		url : prefix + "/add",
	        		data : {
	        			"gardenNo": gardenNo,
	        			"productType": productType,
	        			"amount": amount,
	        			"remark": remark
	        		},
	        		async : false,
	        		error : function(request) {
	        			$.modal.alertError("系统错误");
	        		},
	        		success : function(data) {
	        			$.operate.saveSuccess(data);
	        		}
	        	});
	        }
	</script>
</body>
</html>
